package com.mycompany.inventory.viewmodel;

import java.sql.Date;
import java.util.ArrayList;
import java.util.List;

import org.zkoss.bind.BindUtils;
import org.zkoss.bind.annotation.BindingParam;
import org.zkoss.bind.annotation.NotifyChange;
import org.zkoss.bind.annotation.Command;
import org.zkoss.bind.annotation.Init;
import org.zkoss.zhtml.Messagebox;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zul.Tab;
import org.zkoss.zul.Window;

import com.mycompany.inventory.persistence.CarrierDAO;
import com.mycompany.inventory.persistence.CardDAO;
import com.mycompany.inventory.persistence.CustomFieldDAO;
import com.mycompany.inventory.persistence.CustomerDAO;
import com.mycompany.inventory.persistence.InventoryDAO;
import com.mycompany.inventory.persistence.PaymentMethodDAO;
import com.mycompany.inventory.persistence.PaymentTermDAO;
import com.mycompany.inventory.persistence.PriceCurrencyDAO;
import com.mycompany.inventory.persistence.TaxSchemeDAO;
import com.mycompany.inventory.pojo.Address;
import com.mycompany.inventory.pojo.Card;
import com.mycompany.inventory.pojo.Carrier;
import com.mycompany.inventory.pojo.Contact;
import com.mycompany.inventory.pojo.CreditCard;
import com.mycompany.inventory.pojo.CustomInfo;
import com.mycompany.inventory.pojo.Customer;
import com.mycompany.inventory.pojo.Inventory;
import com.mycompany.inventory.pojo.PaymentMethod;
import com.mycompany.inventory.pojo.PaymentTerm;
import com.mycompany.inventory.pojo.PriceCurrency;
import com.mycompany.inventory.pojo.TaxScheme;


public class CustomerViewModel {
	private String name;
	private String remark;
	private int discount;
	private int taxExempt;
	private double balanca;
	private Date origin;
	private String source;
	boolean disableAddAddressFlag;

	private Customer selectedCustomer;
	private List<Customer> customers = new ArrayList();	

	//payment term
	private PaymentTerm selectedPaymentTerm;
	private List<PaymentTerm> paymentTerms = new ArrayList();
	
	//payment method
	private PaymentMethod selectedPaymetMenthod;
	private List<PaymentMethod> paymentMethod = new ArrayList<PaymentMethod>();	
	
	//tax schema
	private TaxScheme selectedTaxScheme;
	private List<TaxScheme> taxSchemes = new ArrayList();
	
	//carrier
	private Carrier selectedCarrier;
	private List<Carrier> carrier = new ArrayList();
	
	//pricing-currency
	private PriceCurrency selectedPricing;
	private List<PriceCurrency> priceCurrency = new ArrayList();

	//Inventory
	private Inventory selectedIventory;
	private List<Inventory> inventory = new ArrayList();
	
	//creditCard
	private CreditCard selectedCreditCard;
	private List<CreditCard> creditCard = new ArrayList();	
	private CreditCard credit = new CreditCard();
	
	//Card
	private Card selectedCard;
	private List<Card> card = new ArrayList<Card>();
	
	// CustomInfo
	private CustomInfo custom;
	private List<CustomInfo> customs = new ArrayList();
	
	// Contact
	private Contact contact = new Contact();	
	//Customer DAO	
	private CustomerDAO customerDAO = new CustomerDAO();
	//address window
	private Address selected;	
	private List<Address> addresses = new ArrayList();	
	private List types = new ArrayList();
	private List cities = new ArrayList();
	private List nation = new ArrayList();

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}
	
	public List<Address> getAddressList() {
		return addresses;
	}
	
	public List getAddressTypes() {
		return types;
	}
	
	public List getAddressCities() {
		return cities;
	}
	
	public List getAddressNation() {
		return nation;
	}
	
	
	public void setSelectedAddress(Address selected) {
		this.selected = selected;
	}

	public Address getSelectedAddress() {
		return selected;
	}

	/**
	 * @return the selectedCustomer
	 */
	public Customer getSelectedCustomer() {
		return selectedCustomer;
	}

	/**
	 * @param selectedCustomer the selectedCustomer to set
	 */
	public void setSelectedCustomer(Customer selectedCustomer) {
		this.selectedCustomer = selectedCustomer;
	}

	/**
	 * @return the customers
	 */
	public List<Customer> getCustomersList() {
		return customers;
	}

	/**
	 * @param customers the customers to set
	 */
	public void setCustomersList(List<Customer> customers) {
		this.customers = customers;
	}

	/**
	 * @return the selectedPaymetMenthod
	 */
	public PaymentMethod getSelectedPaymetMenthod() {
		return selectedPaymetMenthod;
	}

	/**
	 * @param selectedPaymetMenthod the selectedPaymetMenthod to set
	 */
	public void setSelectedPaymetMenthod(PaymentMethod selectedPaymetMenthod) {
		this.selectedPaymetMenthod = selectedPaymetMenthod;
	}

	/**
	 * @return the paymentMethod
	 */
	public List<PaymentMethod> getPaymentMethod() {
		return paymentMethod;
	}

	/**
	 * @param paymentMethod the paymentMethod to set
	 */
	public void setPaymentMethod(List<PaymentMethod> paymentMethod) {
		this.paymentMethod = paymentMethod;
	}

	/**
	 * @return the selectedCarrier
	 */
	public Carrier getSelectedCarrier() {
		return selectedCarrier;
	}

	/**
	 * @param selectedCarrier the selectedCarrier to set
	 */
	public void setSelectedCarrier(Carrier selectedCarrier) {
		this.selectedCarrier = selectedCarrier;
	}

	/**
	 * @return the carrier
	 */
	public List<Carrier> getCarrier() {
		return carrier;
	}

	/**
	 * @param carrier the carrier to set
	 */
	public void setCarrier(List<Carrier> carrier) {
		this.carrier = carrier;
	}

	/**
	 * @return the selectedIventory
	 */
	public Inventory getSelectedIventory() {
		return selectedIventory;
	}

	/**
	 * @param selectedIventory the selectedIventory to set
	 */
	public void setSelectedIventory(Inventory selectedIventory) {
		this.selectedIventory = selectedIventory;
	}

	/**
	 * @return the inventory
	 */
	public List<Inventory> getInventory() {
		return inventory;
	}

	/**
	 * @param inventory the inventory to set
	 */
	public void setInventory(List<Inventory> inventory) {
		this.inventory = inventory;
	}
	
	/**
	 * @return the selectedCreditCard
	 */
	public CreditCard getSelectedCreditCard() {
		return selectedCreditCard;
	}

	/**
	 * @param selectedCreditCard the selectedCreditCard to set
	 */
	public void setSelectedCreditCard(CreditCard selectedCreditCard) {
		this.selectedCreditCard = selectedCreditCard;
	}

	/**
	 * @return the creditCard
	 */
	public List<CreditCard> getCreditCard() {
		return creditCard;
	}

	/**
	 * @param creditCard the creditCard to set
	 */
	public void setCreditCard(List<CreditCard> creditCard) {
		this.creditCard = creditCard;
	}

	/**
	 * @return the credit
	 */
	public CreditCard getCredit() {
		return credit;
	}

	/**
	 * @param credit the credit to set
	 */
	public void setCredit(CreditCard credit) {
		this.credit = credit;
	}

	/**
	 * @return the selectedCard
	 */
	public Card getSelectedCard() {
		return selectedCard;
	}

	/**
	 * @param selectedCard the selectedCard to set
	 */
	public void setSelectedCard(Card selectedCard) {
		this.selectedCard = selectedCard;
	}

	/**
	 * @return the card
	 */
	public List<Card> getCard() {
		return card;
	}

	/**
	 * @param card the card to set
	 */
	public void setCard(List<Card> card) {
		this.card = card;
	}

	/**
	 * @return the origin
	 */
	public Date getOrigin() {
		return origin;
	}

	/**
	 * @param origin the origin to set
	 */
	public void setOrigin(Date origin) {
		this.origin = origin;
	}

	/**
	 * @return the source
	 */
	public String getSource() {
		return source;
	}

	/**
	 * @param source the source to set
	 */
	public void setSource(String source) {
		this.source = source;
	}

	/**
	 * @return the remark
	 */
	public String getRemark() {
		return remark;
	}

	/**
	 * @param remark the remark to set
	 */
	public void setRemark(String remark) {
		this.remark = remark;
	}

	/**
	 * @return the discount
	 */
	public int getDiscount() {
		return discount;
	}

	/**
	 * @param discount the discount to set
	 */
	public void setDiscount(int discount) {
		this.discount = discount;
	}

	/**
	 * @return the taxExempt
	 */
	public int getTaxExempt() {
		return taxExempt;
	}

	/**
	 * @param taxExempt the taxExempt to set
	 */
	public void setTaxExempt(int taxExempt) {
		this.taxExempt = taxExempt;
	}

	/**
	 * @return the selectedPaymentTerm
	 */
	public PaymentTerm getSelectedPaymentTerm() {
		return selectedPaymentTerm;
	}

	/**
	 * @param selectedPaymentTerm the selectedPaymentTerm to set
	 */
	public void setSelectedPaymentTerm(PaymentTerm selectedPaymentTerm) {
		this.selectedPaymentTerm = selectedPaymentTerm;
	}

	/**
	 * @return the paymentTerms
	 */
	public List<PaymentTerm> getPaymentTerms() {
		return paymentTerms;
	}

	/**
	 * @param paymentTerms the paymentTerms to set
	 */
	public void setPaymentTerms(List<PaymentTerm> paymentTerms) {
		this.paymentTerms = paymentTerms;
	}

	/**
	 * @return the balanca
	 */
	public double getBalanca() {
		return balanca;
	}

	/**
	 * @param balanca the balanca to set
	 */
	public void setBalanca(double balanca) {
		this.balanca = balanca;
	}

	/**
	 * @return the selectedPricing
	 */
	public PriceCurrency getSelectedPricing() {
		return selectedPricing;
	}

	/**
	 * @param selectedPricing the selectedPricing to set
	 */
	public void setSelectedPricing(PriceCurrency selectedPricing) {
		this.selectedPricing = selectedPricing;
	}

	/**
	 * @return the priceCurrency
	 */
	public List<PriceCurrency> getPriceCurrency() {
		return priceCurrency;
	}

	/**
	 * @param priceCurrency the priceCurrency to set
	 */
	public void setPriceCurrency(List<PriceCurrency> priceCurrency) {
		this.priceCurrency = priceCurrency;
	}

	/**
	 * @return the selectedTaxScheme
	 */
	public TaxScheme getSelectedTaxScheme() {
		return selectedTaxScheme;
	}

	/**
	 * @param selectedTaxScheme the selectedTaxScheme to set
	 */
	public void setSelectedTaxScheme(TaxScheme selectedTaxScheme) {
		this.selectedTaxScheme = selectedTaxScheme;
	}

	/**
	 * @return the taxSchemes
	 */
	public List<TaxScheme> getTaxSchemes() {
		return taxSchemes;
	}

	/**
	 * @param taxSchemes the taxSchemes to set
	 */
	public void setTaxSchemes(List<TaxScheme> taxSchemes) {
		this.taxSchemes = taxSchemes;
	}


	/**
	 * @return the custom
	 */
	public CustomInfo getCustom() {
		return custom;
	}

	/**
	 * @param custom the custom to set
	 */
	public void setCustom(CustomInfo custom) {
		this.custom = custom;
	}

	/**
	 * @return the customs
	 */
	public List<CustomInfo> getCustomFieldList() {
		return customs;
	}

	/**
	 * @param customs the customs to set
	 */
	public void setCustoms(List<CustomInfo> customs) {
		this.customs = customs;
	}

	/**
	 * @return the contact
	 */
	public Contact getContact() {
		return contact;
	}

	/**
	 * @param contact the contact to set
	 */
	public void setContact(Contact contact) {
		this.contact = contact;
	}

	/**
	 * @return the selected
	 */
	public Address getSelected() {
		return selected;
	}

	/**
	 * @param selected the selected to set
	 */
	public void setSelected(Address selected) {
		this.selected = selected;
	}

	/**
	 * @return the addresses
	 */
	public List<Address> getAddresses() {
		return addresses;
	}

	/**
	 * @param addresses the addresses to set
	 */
	public void setAddresses(List<Address> addresses) {
		this.addresses = addresses;
	}

	/**
	 * @return the types
	 */
	public List getTypes() {
		return types;
	}

	/**
	 * @param types the types to set
	 */
	public void setTypes(List types) {
		this.types = types;
	}

	/**
	 * @return the cities
	 */
	public List getCities() {
		return cities;
	}

	/**
	 * @param cities the cities to set
	 */
	public void setCities(List cities) {
		this.cities = cities;
	}

	/**
	 * @return the nation
	 */
	public List getNation() {
		return nation;
	}

	/**
	 * @param nation the nation to set
	 */
	public void setNation(List nation) {
		this.nation = nation;
	}

	/**
	 * @return the disableAddAddressFlag
	 */
	public boolean isDisableAddAddressFlag() {
		return disableAddAddressFlag;
	}

	/**
	 * @param disableAddAddressFlag the disableAddAddressFlag to set
	 */
	public void setDisableAddAddressFlag(boolean disableAddAddressFlag) {
		this.disableAddAddressFlag = disableAddAddressFlag;
	}

	@Init
	public void init() {
		this.updateCustomerDetail();
		this.updateCustomerList();
		disableAddAddressFlag = false;
	}

	/*
	 * update function
	 */
	private void updateCustomerList(){
		// init customer list	
		customers = customerDAO.findAll();
		selectedCustomer = (customers == null || customers.size() == 0) ? null : customers.get(0);
	}
	
	private void updateCustomerDetail(){
				
		this.updateAddress();
		
		this.updateCustomField();
		
		this.updatePricing();
		
		this.updatePaymentTerm();
		
		this.updatePaymentMethod();
		
		this.updateTaxScheme();
		
		this.updateCarrier();
		
		this.updateCard();
		
		this.updateInventory();
	}
	
	private void updateAddress(){
		addresses.add(new Address("", "", "", "", "", ""));
		addresses.add(new Address("", "", "", "", "", ""));
		addresses.add(new Address("", "", "", "", "", ""));
		addresses.add(new Address("", "", "", "", "", ""));
		selected = new Address();
		
		//init address popup
		types.add("Commercial");
		types.add("Residential");

		cities.add("Ho Chi Minh");
		cities.add("Da nang");

		nation.add("Viet Nam");
		nation.add("Lao");

	}
	
	private void updateCustomField(){
		// init custom field
		CustomFieldDAO dao = new CustomFieldDAO();
		customs = dao.findAll("Customer");		
		custom = new CustomInfo();
	}
	
	private void updatePricing(){
		//init payment term
		PriceCurrencyDAO dao = new PriceCurrencyDAO();
		priceCurrency = dao.findAll();
		selectedPricing = new PriceCurrency("", "", 0);
	}	

	private void updatePaymentTerm(){
		//init payment term
		PaymentTermDAO dao = new PaymentTermDAO();
		paymentTerms = dao.findAll();
		selectedPaymentTerm = new PaymentTerm("", "", "", 0);
	}

	private void updatePaymentMethod(){
		//init payment term
		PaymentMethodDAO dao = new PaymentMethodDAO();
		paymentMethod = dao.findAll();
		selectedPaymetMenthod = new PaymentMethod("", "");
	}	
	
	private void updateTaxScheme(){
		//init tax Schemes
		TaxSchemeDAO dao = new TaxSchemeDAO();
		taxSchemes = dao.findAll();
		selectedTaxScheme = new TaxScheme("", "", "", "", 0);
	}
	
	private void updateInventory(){
		//init payment method
		InventoryDAO dao = new InventoryDAO();
		inventory = dao.findAll();
		selectedIventory = new Inventory("", "", 0);
	}	

	private void updateCard(){
		//init payment method
		CardDAO dao = new CardDAO();
		card = dao.findAll();
		selectedCard = new Card("", "");
	}
	
	private void updateCarrier(){
		//init carrier
		CarrierDAO dao = new CarrierDAO();
		carrier = dao.findAll();
		selectedCarrier = new Carrier("", "", "");
	}
	
	/*
	 * command function
	 */
	
	//popup command
	@NotifyChange({"addresses", "disableAddAddressFlag"})
	@Command
	public void newAddress(@BindingParam("dlg") Window win) {
		// manipulate data		
		for (Address add : addresses){
			if(add.getAddress().equals("")){
				add.setId(selected.getId());
				add.setAddress(selected.getAddress());
				add.setCity(selected.getCity());
				add.setNational(selected.getNational());
				add.setRemark(selected.getRemark());
				add.setType(selected.getType());
				break;
			}
		}
		updateButtonStatus();
		win.onClose();
	}	
	
	private void updateButtonStatus(){
		if(addresses.get(3).getAddress().equals("")){
			 disableAddAddressFlag = false;
		}else{
			disableAddAddressFlag = true;
		}
	}	
	
	@NotifyChange("customs")
	@Command
	public void updateCustomField(@BindingParam("dlg") Window win) {
		// manipulate data
		// addresses.add(new
		// Address(selected.getAddress(),selected.getCity(),selected.getNational(),selected.getRemark(),selected.getType()));
		//customs.add(new CustomInfo(custom.getName(), custom.getValue(),"","",true));
		win.onClose();
	}

	
	//customer list command
	@NotifyChange({ "name", "contact", "addresses" , "discount", "taxExempt", "customs" , "selectedPaymentTerm" , "selectedTaxScheme" , "selectedCarrier","selectedPricing"})
	@Command
	public void selectTabInfo() {
		if(selectedCustomer == null){ 			
			return;		
		}
		processEditCustomer();
	}
	
	@NotifyChange("customers")
	@Command
	public void refreshList() {
		updateCustomerList();
	}	
	
	@NotifyChange({ "name", "contact", "addresses", "customs", "discount", "taxExempt", "selectedPaymentTerm" , "selectedTaxScheme" , "selectedPricing" , "selectedPaymetMenthod", "disableAddAddressFlag"})
	@Command
	public void editCustomer(@BindingParam("para") Component tab) {
		Tab t = (Tab)tab;
		if(selectedCustomer == null){
			Messagebox.show("No Vendor", "Information", Messagebox.OK, Messagebox.INFORMATION);
			return;
		}
		processEditCustomer();
		t.setSelected(true);
	}
	
	@NotifyChange({ "name", "contact", "addresses" , "customs" , "discount", "taxExempt", "selectedPaymentTerm" , "selectedTaxScheme" , "selectedPricing" , "selectedPaymetMenthod", "disableAddAddressFlag"})
	@Command
	public void createCustomer(@BindingParam("para") Component tab) {
		Tab t = (Tab)tab;
		name = "";
		remark = "";
		discount = 0;
		taxExempt = 0;
		balanca = 0.0;
		contact.clear();	
		for (Address add : addresses){
			add.clear();
		}
		for (CustomInfo cus : customs){
			cus.clear();
		}
		selectedPaymentTerm = null;
		selectedTaxScheme = null;
		selectedCarrier = null;
		selectedPaymetMenthod = null;
		selectedCreditCard = null;
		selectedIventory = null;
		selectedCustomer = null;
		disableAddAddressFlag = false;
		
		t.setSelected(true);
	}
	
	@NotifyChange("customers")
	@Command
	public void deleteCustomer() {	
		if(selectedCustomer == null){ 
			Messagebox.show("No Customer", "Information", Messagebox.OK, Messagebox.INFORMATION);
			return;		
		}		
		//Messagebox.show("Are you sure to delete?", "Confirm Dialog", Messagebox.OK | Messagebox.CANCEL, Messagebox.QUESTION, this); 
		
		customerDAO.delete(selectedCustomer);	
    	updateCustomerList();  
	}
		
	public void onEvent(Event evt) throws InterruptedException {
        if (evt.getName().equals("onOK")) {
        	customerDAO.delete(selectedCustomer);	
        	updateCustomerList();  
        	BindUtils.postNotifyChange(null,null,this,"customers");
        } else {	
        	return;
        }
    }
	
	//vendor detail command	
	@NotifyChange("customers")
	@Command("save")
	public void newCustomer(@BindingParam("para") Component tab) {	
		Customer customer;
		if(selectedCustomer == null){
			customer = new Customer("9", name, 0, remark, discount, addresses, contact, selectedPricing, selectedPaymentTerm, selectedTaxScheme, taxExempt, selectedPaymetMenthod, selectedCarrier, selectedIventory, selectedCreditCard, origin, source, customs);
			customerDAO.create(customer);
		}else{
			customer = new Customer(selectedCustomer.getId(),name, 0, remark, discount, addresses, contact, selectedPricing, selectedPaymentTerm, selectedTaxScheme, taxExempt, selectedPaymetMenthod, selectedCarrier, selectedIventory, selectedCreditCard, origin, source, customs);
			customerDAO.update(customer);
		}
		updateCustomerList();
		Tab t = (Tab)tab;
		t.setSelected(true);
	}	
	
	private void processEditCustomer(){
		name = selectedCustomer.getName();
		remark = selectedCustomer.getRemark();
		discount = selectedCustomer.getDiscount();
		if(selectedCustomer.getContact()!= null)
			contact.copyValue(selectedCustomer.getContact());
		
		for (int i = 0 ; i < 4 ;i++){
			if(i < selectedCustomer.getAddresses().size() ){
				addresses.get(i).copyValue(selectedCustomer.getAddresses().get(i));
			}else{
				addresses.get(i).clear();
			}						
		}		
		
		updateButtonStatus();		
		
		for (int i = 0 ; i < selectedCustomer.getAddresses().size() ;i++){
			addresses.get(i).copyValue(selectedCustomer.getAddresses().get(i));
		}			
		for (int i = 0 ; i < customs.size() ;i++){
			customs.get(i).copyValue(selectedCustomer.getCustoms().get(i));
		}
		
		if(priceCurrency!= null && selectedCustomer.getPrice() != null)
			for (int i = 0 ; i < priceCurrency.size() ;i++){
				if(priceCurrency.get(i).getName().equals(selectedCustomer.getPrice().getName())){
					selectedPricing = priceCurrency.get(i);
					break;
				}
			}		
		
		if(paymentTerms!= null && selectedCustomer.getPaymentTerm() != null)
			for (int i = 0 ; i < paymentTerms.size() ;i++){
				if(paymentTerms.get(i).getName().equals(selectedCustomer.getPaymentTerm().getName())){
					selectedPaymentTerm = paymentTerms.get(i);
					break;
				}
			}
		
		if(taxSchemes!= null && selectedCustomer.getTaxingScheme() != null)
			for (int i = 0 ; i < taxSchemes.size() ;i++){
				if(taxSchemes.get(i).getName().equals(selectedCustomer.getTaxingScheme().getName())){
					selectedTaxScheme = taxSchemes.get(i);
					break;
				}
			}
		
		this.taxExempt = selectedCustomer.getTaxexempt();				
	}
	
	@NotifyChange({ "selectedIventory","selectedPaymetMenthod", "selectedCarrier", "creditCard", "selectedCard", "credit", "origin", "source"})
	@Command
	public void selectTabExtra(@BindingParam("para") Component tab) {
		Tab t = (Tab)tab;
		if(selectedCustomer == null){
			Messagebox.show("Please choice a customer!", "Information", Messagebox.OK, Messagebox.INFORMATION);
			return;
		}
		editExtraCustomer();
		t.setSelected(true);
	}
	
	private void editExtraCustomer(){
		if(selectedCustomer.getCreditCard()!= null){
			credit.copyValue(selectedCustomer.getCreditCard());
			selectedCard = new CardDAO().findByName(selectedCustomer.getCreditCard().getCardType());
		}
		
		
		if(inventory!= null && selectedCustomer.getInventory() != null)
			for (int i = 0 ; i < inventory.size() ;i++){
				if(inventory.get(i).getName().equals(selectedCustomer.getInventory().getName())){
					selectedIventory = inventory.get(i);
					break;
				}
			}		
		
		if(paymentMethod!= null && selectedCustomer.getPaymentMethod() != null)
			for (int i = 0 ; i < paymentMethod.size() ;i++){
				if(paymentMethod.get(i).getName().equals(selectedCustomer.getPaymentMethod().getName())){
					selectedPaymetMenthod = paymentMethod.get(i);
					break;
				}
			}
		
		if(carrier!= null && selectedCustomer.getCarrier() != null)
			for (int i = 0 ; i < carrier.size() ;i++){
				if(carrier.get(i).getName().equals(selectedCustomer.getCarrier().getName())){
					selectedCarrier = carrier.get(i);
					break;
				}
			}
		
		this.origin = selectedCustomer.getOrigin();
		this.source = selectedCustomer.getSource();				
	}
	
	@NotifyChange("customers")
	@Command("saveExtra")
	public void updateExtraCustomer(@BindingParam("para") Component tab) {	
		Customer customer;
		customer = new Customer(selectedCustomer.getId(), selectedPaymetMenthod, selectedCarrier, selectedIventory, credit, origin, source);
		customerDAO.updateExtra(customer);

		updateCustomerList();
		Tab t = (Tab)tab;
		t.setSelected(true);
	}		
}